// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Cloud Document AI API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_documentai_v1::client::DocumentProcessorService;
/// let client = DocumentProcessorService::builder().build().await?;
/// // use `client` to make requests to the Cloud Document AI API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Service to call Document AI to process documents according to the
/// processor's definition. Processors are built using state-of-the-art Google
/// AI such as natural language, computer vision, and translation to extract
/// structured information from unstructured or semi-structured documents.
///
/// # Configuration
///
/// To configure `DocumentProcessorService` use the `with_*` methods in the type returned
/// by [builder()][DocumentProcessorService::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://documentai.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::document_processor_service::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::document_processor_service::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `DocumentProcessorService` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `DocumentProcessorService` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct DocumentProcessorService {
    inner: std::sync::Arc<dyn super::stub::dynamic::DocumentProcessorService>,
}

impl DocumentProcessorService {
    /// Returns a builder for [DocumentProcessorService].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_documentai_v1::client::DocumentProcessorService;
    /// let client = DocumentProcessorService::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::document_processor_service::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::document_processor_service::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::DocumentProcessorService + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<
        std::sync::Arc<dyn super::stub::dynamic::DocumentProcessorService>,
    > {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::DocumentProcessorService> {
        super::transport::DocumentProcessorService::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::DocumentProcessorService> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::DocumentProcessorService::new)
    }

    /// Processes a single document.
    pub fn process_document(&self) -> super::builder::document_processor_service::ProcessDocument {
        super::builder::document_processor_service::ProcessDocument::new(self.inner.clone())
    }

    /// LRO endpoint to batch process many documents. The output is written
    /// to Cloud Storage as JSON in the [Document] format.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn batch_process_documents(
        &self,
    ) -> super::builder::document_processor_service::BatchProcessDocuments {
        super::builder::document_processor_service::BatchProcessDocuments::new(self.inner.clone())
    }

    /// Fetches processor types. Note that we don't use
    /// [ListProcessorTypes][google.cloud.documentai.v1.DocumentProcessorService.ListProcessorTypes]
    /// here, because it isn't paginated.
    ///
    /// [google.cloud.documentai.v1.DocumentProcessorService.ListProcessorTypes]: crate::client::DocumentProcessorService::list_processor_types
    pub fn fetch_processor_types(
        &self,
    ) -> super::builder::document_processor_service::FetchProcessorTypes {
        super::builder::document_processor_service::FetchProcessorTypes::new(self.inner.clone())
    }

    /// Lists the processor types that exist.
    pub fn list_processor_types(
        &self,
    ) -> super::builder::document_processor_service::ListProcessorTypes {
        super::builder::document_processor_service::ListProcessorTypes::new(self.inner.clone())
    }

    /// Gets a processor type detail.
    pub fn get_processor_type(
        &self,
    ) -> super::builder::document_processor_service::GetProcessorType {
        super::builder::document_processor_service::GetProcessorType::new(self.inner.clone())
    }

    /// Lists all processors which belong to this project.
    pub fn list_processors(&self) -> super::builder::document_processor_service::ListProcessors {
        super::builder::document_processor_service::ListProcessors::new(self.inner.clone())
    }

    /// Gets a processor detail.
    pub fn get_processor(&self) -> super::builder::document_processor_service::GetProcessor {
        super::builder::document_processor_service::GetProcessor::new(self.inner.clone())
    }

    /// Trains a new processor version.
    /// Operation metadata is returned as
    /// [TrainProcessorVersionMetadata][google.cloud.documentai.v1.TrainProcessorVersionMetadata].
    ///
    /// [google.cloud.documentai.v1.TrainProcessorVersionMetadata]: crate::model::TrainProcessorVersionMetadata
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn train_processor_version(
        &self,
    ) -> super::builder::document_processor_service::TrainProcessorVersion {
        super::builder::document_processor_service::TrainProcessorVersion::new(self.inner.clone())
    }

    /// Gets a processor version detail.
    pub fn get_processor_version(
        &self,
    ) -> super::builder::document_processor_service::GetProcessorVersion {
        super::builder::document_processor_service::GetProcessorVersion::new(self.inner.clone())
    }

    /// Lists all versions of a processor.
    pub fn list_processor_versions(
        &self,
    ) -> super::builder::document_processor_service::ListProcessorVersions {
        super::builder::document_processor_service::ListProcessorVersions::new(self.inner.clone())
    }

    /// Deletes the processor version, all artifacts under the processor version
    /// will be deleted.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_processor_version(
        &self,
    ) -> super::builder::document_processor_service::DeleteProcessorVersion {
        super::builder::document_processor_service::DeleteProcessorVersion::new(self.inner.clone())
    }

    /// Deploys the processor version.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn deploy_processor_version(
        &self,
    ) -> super::builder::document_processor_service::DeployProcessorVersion {
        super::builder::document_processor_service::DeployProcessorVersion::new(self.inner.clone())
    }

    /// Undeploys the processor version.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn undeploy_processor_version(
        &self,
    ) -> super::builder::document_processor_service::UndeployProcessorVersion {
        super::builder::document_processor_service::UndeployProcessorVersion::new(
            self.inner.clone(),
        )
    }

    /// Creates a processor from the
    /// [ProcessorType][google.cloud.documentai.v1.ProcessorType] provided. The
    /// processor will be at `ENABLED` state by default after its creation. Note
    /// that this method requires the `documentai.processors.create` permission on
    /// the project, which is highly privileged. A user or service account with
    /// this permission can create new processors that can interact with any gcs
    /// bucket in your project.
    ///
    /// [google.cloud.documentai.v1.ProcessorType]: crate::model::ProcessorType
    pub fn create_processor(&self) -> super::builder::document_processor_service::CreateProcessor {
        super::builder::document_processor_service::CreateProcessor::new(self.inner.clone())
    }

    /// Deletes the processor, unloads all deployed model artifacts if it was
    /// enabled and then deletes all artifacts associated with this processor.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_processor(&self) -> super::builder::document_processor_service::DeleteProcessor {
        super::builder::document_processor_service::DeleteProcessor::new(self.inner.clone())
    }

    /// Enables a processor
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn enable_processor(&self) -> super::builder::document_processor_service::EnableProcessor {
        super::builder::document_processor_service::EnableProcessor::new(self.inner.clone())
    }

    /// Disables a processor
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn disable_processor(
        &self,
    ) -> super::builder::document_processor_service::DisableProcessor {
        super::builder::document_processor_service::DisableProcessor::new(self.inner.clone())
    }

    /// Set the default (active) version of a
    /// [Processor][google.cloud.documentai.v1.Processor] that will be used in
    /// [ProcessDocument][google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument]
    /// and
    /// [BatchProcessDocuments][google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments].
    ///
    /// [google.cloud.documentai.v1.DocumentProcessorService.BatchProcessDocuments]: crate::client::DocumentProcessorService::batch_process_documents
    /// [google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument]: crate::client::DocumentProcessorService::process_document
    /// [google.cloud.documentai.v1.Processor]: crate::model::Processor
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn set_default_processor_version(
        &self,
    ) -> super::builder::document_processor_service::SetDefaultProcessorVersion {
        super::builder::document_processor_service::SetDefaultProcessorVersion::new(
            self.inner.clone(),
        )
    }

    /// Send a document for Human Review. The input document should be processed by
    /// the specified processor.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn review_document(&self) -> super::builder::document_processor_service::ReviewDocument {
        super::builder::document_processor_service::ReviewDocument::new(self.inner.clone())
    }

    /// Evaluates a ProcessorVersion against annotated documents, producing an
    /// Evaluation.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn evaluate_processor_version(
        &self,
    ) -> super::builder::document_processor_service::EvaluateProcessorVersion {
        super::builder::document_processor_service::EvaluateProcessorVersion::new(
            self.inner.clone(),
        )
    }

    /// Retrieves a specific evaluation.
    pub fn get_evaluation(&self) -> super::builder::document_processor_service::GetEvaluation {
        super::builder::document_processor_service::GetEvaluation::new(self.inner.clone())
    }

    /// Retrieves a set of evaluations for a given processor version.
    pub fn list_evaluations(&self) -> super::builder::document_processor_service::ListEvaluations {
        super::builder::document_processor_service::ListEvaluations::new(self.inner.clone())
    }

    /// Lists information about the supported locations for this service.
    pub fn list_locations(&self) -> super::builder::document_processor_service::ListLocations {
        super::builder::document_processor_service::ListLocations::new(self.inner.clone())
    }

    /// Gets information about a location.
    pub fn get_location(&self) -> super::builder::document_processor_service::GetLocation {
        super::builder::document_processor_service::GetLocation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::document_processor_service::ListOperations {
        super::builder::document_processor_service::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::document_processor_service::GetOperation {
        super::builder::document_processor_service::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::document_processor_service::CancelOperation {
        super::builder::document_processor_service::CancelOperation::new(self.inner.clone())
    }
}
